<template>
  <div>
    echarts数据展示
    <div id="maincharts" style="height:600px"></div>
  </div>
</template>

<script>
import axios from '@/service/index.js';
import * as echarts from 'echarts';
export default {
  data() {
    return {
      list: [],
      myChart: null
    };
  },
  created() {
    axios.get('/data/simpleData').then(res => {
      if (res.code === '200') {
        this.list = res.data;
        this.drawChart(this.list);
      }
    });
  },
  mounted() {
    this.myChart = echarts.init(document.getElementById('maincharts'));
  },
  methods: {
    drawChart(list) {
      this.myChart.setOption({
        title: {
          text: 'ECharts 入门示例'
        },
        tooltip: {},
        xAxis: {
          data: list.map(item => item.x)
        },
        toolbox: {
          show: true,
          feature: {
            dataZoom: {
              yAxisIndex: 'none'
            },
            dataView: { show: true, readOnly: false },
            magicType: { type: ['line', 'bar'] },
            restore: { show: true },
            saveAsImage: { show: true }
          }
        },
        yAxis: {},
        series: [
          {
            name: 'Nightingale Chart',
            type: 'pie',
            radius: [50, 250],
            center: ['50%', '50%'],
            roseType: 'area',
            itemStyle: {
              borderRadius: 8
            },
            data: list.map((item, index) => ({ value: item.val, name: item.x }))
          },
          {
            name: '销量a',
            type: 'line',
            data: list.map(item => item.val)
          },
          {
            name: '销量b',
            type: 'bar',
            data: list.map(item => item.val)
          }
        ]
      });
    }
  }
};
</script>
<style scoped>
</style>